package com.zkthink.ceres.msgs.controller;


import com.zkthink.base.R;
import com.zkthink.ceres.msgs.dto.MobilePushDTO;
import com.zkthink.ceres.msgs.service.MobilePushService;
import com.zkthink.security.annotation.PreAuth;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * FileName: MobilePushController
 * Author:   Pepis
 * Date:   2020  2020/8/29 18:14
 * Description: 阿里云 移动推送
 **/
@Slf4j
@RestController
@RequestMapping("/MobilePush")
@Api(value = "MobilePush", tags = "移动推送")
@Validated
@PreAuth(replace = "MobilePush:")
public class MobilePushController {
    @Autowired
    private MobilePushService mobilePushService;

    /**
     * 推送消息 给某个用户 /某些用户
     *
     * @param mobilePushDTO
     * @return
     */
    @PostMapping("/push")
    public R pushMsg(@RequestBody @Validated MobilePushDTO mobilePushDTO) {
        return R.success(mobilePushService.pushMsg(mobilePushDTO));
    }

    /**
     * 全量推送,给所有用户推送
     * @param mobilePushDTO
     * @return
     */
    @PostMapping("/pushAll")
    public R pushMsgAll(@RequestBody @Validated MobilePushDTO mobilePushDTO) {
        mobilePushService.pushMsgAll(mobilePushDTO);
        return R.success();
    }
}
